
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Demo {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String[] s = in.nextLine().split("-");//s[0] / s[1] / ERROR
            String[] s1 = s[0].split(" ");
            String[] s2 = s[1].split(" ");
            String p = "34567891JQKA2";
            if (s[0].equals("joker JOKER") || s[1].equals("joker JOKER")) {
                System.out.println("joker JOKER");
            }else if(s1.length == s2.length){
                if(p.indexOf(s[0].substring(0,1))>p.indexOf(s[1].substring(0,1))){
                    System.out.println(s[0]);
                }else if(p.indexOf(s[0].substring(0,1))<p.indexOf(s[1].substring(0,1))){
                    System.out.println(s[1]);
                }
            } else if(s1.length == 4) {
                System.out.println(s[0]);
            } else if(s2.length == 4){
                System.out.println(s[1]);
            } else {
                System.out.println("ERROR");
            }
        }
    }
}


class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int num = in.nextInt();
            if(num == 1 || num == 2){
                System.out.println(-1);
                continue;
            }
            else if(num % 4 == 1 || num % 4 == 3){
                System.out.println(2);
                continue;
            }
            else if(num % 4 == 0){
                System.out.println(3);
                continue;
            }
            else if(num % 4 == 2){
                System.out.println(4);
                continue;
            }
        }
    }
}